<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script type="text/javascript" src="./js/jquery-1.8.3.min.js"></script>
    <script>
//一、基本用法： 
        // (1) extend(dest,src1,src2,src3...);    是将src1,src2,src3...合并到dest中,返回值为合并后的dest,
        var dest = {name:"xx",read:"yes"};
        $.extend(dest,{name:"kathy",age:"29"},{name:"cgg",sex:"male"});
        console.log(dest);
        // Object {name: "cgg", read: "yes", age: "29", sex: "male"}
        // 返回值为合并后的dest,由此可以看出该方法合并后，是修改了dest的结构的。


        // (2) var newSrc=$.extend({},src1,src2,src3...)    如果想要得到合并的结果却又不想修改dest的结构
        var  newSrc = $.extend({},{name:"kathy",age:"29"},{name:"cgg",sex:"male"});
        console.log(newSrc);
        // Object {name: "cgg", age: "29", sex: "male"} 


//二、省略dest参数   该方法就只能有一个src参数
        // (1) $.extend(src)  将hello方法合并到jquery的全局对象中
        $.extend({
            hello1:function(){alert("hello1");}
        });
        $.hello1();

        // (2) $.fn.extend(src)    hello方法合并到jquery的实例对象中
        $.fn.extend({
            hello2:function(){alert('hello2');}
        });
        var $callhello2 = $("#call");
        $callhello2.hello2();
        // $.fn.hello2();


        //eg:在jquery全局对象中扩展一个net命名空间
        $.extend({
            net:{}
        });

        $.extend($.net,{
            hello3:function(){alert("hello3");}
        });
        $.net.hello3();


      /*  $.fn.waterfall = function(){
            alert("hello4");
        }
        $.fn.waterfall.defaults = {
            img: "wf-img",
            url: "xxx"
        }
        $callhello2.waterfall();
        console.log($.fn.waterfall.defaults);*/


// 三、Jquery的extend方法还有一个重载原型：
//      extend(boolean,dest,src1,src2,src3...)         第一个参数boolean代表是否进行深度拷贝，  默认false
        var result = $.extend(true,{},
                {name:"kathy",location:{city:"HZ",country:"China"}},
                {account:"cgg",location:{state:"MA",country:"USA"}});
        console.log(result);
        // Object {name: "kathy", location: {city:"HZ",country:"USA",state:"MA"}, account: "cgg"}
 
        var kathy = {name:"kathy",location:{city:"HZ",country:"China"}};
        var cgg =   {account:"cgg",location:{state:"MA",country:"USA"}}
        var result = $.extend(kathy,cgg);
        console.log(result);
        // Object {name: "kathy", location: {country:"USA",state:"MA"}, account: "cgg"}

        console.log(kathy);  //合并后到kathy对象中
        // Object {name: "kathy", location: {country:"USA",state:"MA"}, account: "cgg"}

        console.log(cgg);
        // Object {location: {country:"USA",state:"MA"}, account: "cgg"}



// 四、看一个实际应用的例子
        function ScrollLazyloadIndex(){
            this.opts = {xx:"xuxuan"};
            this.conf = function(){
                var defaults = {
                    isManualMod : false,//是否手动模式
                    isNeedScrollLoad : true,//是否需要延迟滚动加载
                    loadedClk : null,
                    allCompletClk : null
                }
                var config = $.extend(true, defaults, this.opts);
                console.log(config);
                console.log(defaults); //都合并到defaluts，defaluts的内容和config的相同
                return config;
            }
        }
        console.log(new ScrollLazyloadIndex().conf());
        // 也可以这么写
        // var sObj = new ScrollLazyloadIndex();
        // console.log(sObj.conf());
    </script>
</head>
<body>
<div id="call"></div>
ref:
http://www.cnblogs.com/RascallySnake/archive/2010/05/07/1729563.html
</body>
</html>